<template>
  <div class="swiper-container">
    <div class="swiper-wrapper">
      <div class="swiper-slide" v-for="(itme,i) in imgs" :key="i">
        <img :src="itme.pic" />
      </div>
    </div>
    <!-- 如果需要分页器 -->
    <div class="swiper-pagination"></div>
  </div>
</template>
<script>
import Swiper from "swiper";
import { getBanners } from "@/api/index.js";

// import style (>= Swiper 6.x)
import "swiper/css/swiper.css";
export default {
  data() {
    return {
      imgs: [
        { pic: require("../assets/img/01.jpg") },
        { pic: require("../assets/img/02.jpg") },
        { pic: require("../assets/img/03.jpg") }
      ]
    };
  },
  async mounted() {
    var mySwiper = new Swiper(".swiper-container", {
      loop: true, // 循环模式选项

      // 如果需要分页器
      pagination: {
        el: ".swiper-pagination"
      }
    });
    let res = await getBanners(2);
    this.imgs = res.data.banners;
  }
};
</script>
<style scoped lang="less">
.swiper-container {
  width: 7.3rem;
  height: 2.84rem;
  background-color: #ccc;
  border-radius: 0.1rem;
  img {
    width: 100%;
  }
}
</style>